#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

int minAreaRect(int** points, int pointsSize, int* pointsColSize) {
	if(pointsSize < 4){
		*pointsColSize = 0;
		return 0;
	}
	*pointsColSize = 2147483647;
	int *index = (int*)malloc(4 * sizeof(int));
	for(index[0] = 0; index[0] < pointsSize && *pointsColSize != 1; index[0]++){
		int x0 = points[index[0]][0], x1;
		int y0 = points[index[0]][1], y1;
		for(index[1] = index[0] + 1; index[1] < pointsSize; index[1]++){
			if(points[index[1]][1] == y0){
				x1 = points[index[1]][0];
				for(index[2] = index[0] + 1; index[2] < pointsSize; index[2]++){
					if(index[2] == index[1]){
						continue;
					}
					if(points[index[2]][0] == x0){
						y1 = points[index[2]][1];
						for(index[3] = index[0] + 1; index[3] < pointsSize; index[3]++){
							if(index[3] == index[2] || index[3] == index[1]){
								continue;
							}
							if(points[index[3]][0] == x1 && points[index[3]][1] == y1){
								int wide = (x0 > x1) ? x0 - x1 : x1 - x0;
								int high = (y0 > y1) ? y0 - y1 : y1 - y0;
								*pointsColSize = (*pointsColSize > wide * high) ? wide * high : *pointsColSize;
							}
						}
					}
				}
			}
		}
	}
	free(index);
	if(*pointsColSize == 2147483647){
		return 0;
	}
	return *pointsColSize;
}

int main () {
	int points[8][2] = {{3,2},{3,1},{4,4},{1,1},{4,3},{0,1},{0,2},{4,0}};
	int *p[8];
	for(int i = 0; i < 8; i++){
		p[i] = points[i];
	}
	int m_a_r = 0;
	printf("%d\n", minAreaRect(p, 8, &m_a_r));
	return 0;
}



